package com.yj.inventory.mapper;

import com.yj.inventory.dto.InventoryUpdateDto;
import com.yj.inventory.entity.Inventory;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/12
 * Author     : Unbelievable9
 **/
@Repository
@Mapper
public interface InventoryMapper {

    @Options(useGeneratedKeys = true, keyProperty = "item.id")
    @Insert("INSERT INTO inventory (user_id, type, name, longitude, latitude, amount, record_time, create_time) " +
            "VALUES(#{item.user_id}, #{item.type}, #{item.name}, #{item.longitude}, " +
            "#{item.latitude}, #{item.amount}, #{item.record_time}, now())")
    void insert(@Param("item") Inventory item);

    @Update("UPDATE inventory SET amount = #{item.amount}, record_time = #{item.record_time}" +
            "WHERE id = #{item.id}")
    void update(@Param("item") InventoryUpdateDto item);
}